
define([ "Zepto", "underscore", "Backbone", "Handlebars",
         "text!templates/hall/listhalls.html",
         "views/hall/halllistitemview",
         "views/common/menuview" ], function($, _, Backbone, Handlebars,
        		 template, HallListItemView, MenuView) {

	var HallListView = Backbone.View.extend({

		template : Handlebars.compile(template),
		initialize : function() {
			this.model.bind("reset", this.render, this);
		},

		render : function(eventName) {
			// menu top
			this.menutop = new MenuView({
				el : $('#menu', this.el),
				model : this.model
			});
			this.menutop.render();
        	
			$(this.el).empty();
			//$('form').remove();
			$('form').remove();
			$('header').empty();
			$('header').html('Lista Aule libere');
			
			_.each(this.model.models, function(hall) {
			//	alert('hall.nome ' + hall.get('nome'));
			  $(this.el).append(new HallListItemView({
			  		tagName : 'div',
			  		className : 'list-item',
					model : hall
				}).render().el);
			
			}, this);
		
			return this;
		},
  
		// postRender : function(eventName) {
		// 	alert('HallListView PostRender()');
		// 	var scrollableframe = new iScroll('scrollableframe', {
		// 		useTransition : false,
		// 		checkDOMChanges : true,
		// 		hideScrollbar : true,
		// 		fixedScrollbar : true,
		// 		bounceLock : true });
		// },

		events : {
			'touchstart .list-item' : 'over',
			'touchend .list-item' : 'left',
			'touchcancel .list-item' : 'left', 
		},

		over : function(event) {
			$(event.currentTarget).addClass('fake-active');
		},

		left : function(event) {
			$(event.currentTarget).removeClass('fake-active');
		}
	});


	return HallListView;


});

